﻿using System.Collections.Generic;
using System.ComponentModel.Composition;
using InvestmentIntelligence.Files;
using InvestmentIntelligence.SchedulingService.Infrastructure;
using InvestmentIntelligence.TradingData.Handlers.Handlers.CsvHandlers;
using InvestmentIntelligence.TradingData.Handlers.Mus.FieldsConfiguration;

namespace InvestmentIntelligence.TradingData.Handlers.Mus
{
    [Export(typeof(IScheduledTaskFactory))]
    [ExportMetadata("TaskName", "LoadMusCsvFundbook")]
    public class CsvMusFundbookHandlerFactory : FolderBasedHandlerFactoryBase, IScheduledTaskFactory
    {
        private readonly ScheduledTaskParameter _fundbooksFile = new StringScheduledTaskParameter(
            "fundbooks-dir", "specifies a fund book directory");

        public override IEnumerable<ScheduledTaskParameter> GetParameters()
        {
            yield return _fundbooksFile;
        }

        public override IScheduledTask CreateTask(CreateTaskParams createTaskParams, IDictionary<ScheduledTaskParameter, string> arguments)
        {
            var fileds = new FundBookFields();
            var files = FilteredFileReader.GetFiles(_fundbooksFile.Get(arguments, ""), "*", "csv");
            return new CsvImportFundbookDataHandler(files, fileds, Mappings.TradingDataFundbookDto);
        }
    }
}